package org.wiw.client.gui;

import java.util.HashMap;
import java.util.Map;

import org.wiw.client.MarkerPlaceStorage;
import org.wiw.client.model.Person;

import com.google.gwt.maps.client.overlay.Marker;

public class FilterModel {
	private MarkerPlaceStorage storage;
	private Map<Long, Boolean>checked;
	
	public FilterModel(MarkerPlaceStorage storage){
		this.storage = storage;
		checked = new HashMap<Long, Boolean>();
	}
	
	public MarkerPlaceStorage getStorage() {
		return storage;
	}
	
	public void apply(){
		for(Marker m : storage.getMarkers()){
			Person p = storage.get(m).getPerson();
			m.setVisible(isChecked(p));
		}
	}
	
	public boolean isChecked(Person p){
		if(checked.containsKey(p.getId())){
			return checked.get(p.getId());
		}
		return true;
	}
	
	public void setChecked(Person p, boolean check){
		checked.put(p.getId(), check);
	}
}
